package com.bocai.freeman.view.activitys;

import android.os.Bundle;
import android.view.View;
import android.widget.RadioButton;
import android.widget.TextView;

import com.bocai.freeman.R;
import com.bocai.freeman.base.BaseActivity;
import com.bocai.freeman.utils.ToolbarHelper;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by admin on 2016/5/19.
 */
public class MyMemberActivity extends BaseActivity implements View.OnClickListener {

    @Bind(R.id.rbt_gold_champion)
    RadioButton mRbtGoldChampion;
    @Bind(R.id.rbt_blue_champion)
    RadioButton mRbtBlueChampion;
    @Bind(R.id.rbt_gold_diamond)
    RadioButton mRbtGoldDiamond;
    @Bind(R.id.rbt_blue_diamond)
    RadioButton mRbtBlueDiamond;
    @Bind(R.id.rbt_gold_vip)
    RadioButton mRbtGoldVip;
    @Bind(R.id.rbt_blue_vip)
    RadioButton mRbtBlueVip;
    @Bind(R.id.tv_num)
    TextView mTvNum;
    @Bind(R.id.tv_level)
    TextView mTvLevel;

    private int POSITION = -1;//用来记录用户上一次操作的位置
    private String[] levels;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my_member);
        ButterKnife.bind(this);
        initEvent();
    }

    @Override
    protected void initEvent() {
        super.initEvent();
        ToolbarHelper.setup(this, R.string.my_member, R.mipmap.left_return);
        mRbtGoldChampion.setOnClickListener(this);
        mRbtBlueChampion.setOnClickListener(this);
        mRbtGoldDiamond.setOnClickListener(this);
        mRbtBlueDiamond.setOnClickListener(this);
        mRbtGoldVip.setOnClickListener(this);
        mRbtBlueVip.setOnClickListener(this);
        levels = getResources().getStringArray(R.array.member_level);
    }

    @Override
    public void setData(Object obj) {
        super.setData(obj);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.rbt_gold_champion:
                if (POSITION != -1 && POSITION == 0) {
                    mRbtGoldChampion.setChecked(false);
                    POSITION = -1;
                } else {
                    setNoChecked(POSITION);
                    POSITION = 0;
                }
                break;
            case R.id.rbt_blue_champion:
                if (POSITION != -1 && POSITION == 1) {
                    mRbtBlueChampion.setChecked(false);
                    POSITION = -1;
                } else {
                    setNoChecked(POSITION);
                    POSITION = 1;
                }
                break;
            case R.id.rbt_gold_diamond:
                if (POSITION != -1 && POSITION == 2) {
                    mRbtGoldDiamond.setChecked(false);
                    POSITION = -1;
                } else {
                    setNoChecked(POSITION);
                    POSITION = 2;
                }
                break;
            case R.id.rbt_blue_diamond:
                if (POSITION != -1 && POSITION == 3) {
                    mRbtBlueDiamond.setChecked(false);
                    POSITION = -1;
                } else {
                    setNoChecked(POSITION);
                    POSITION = 3;
                }
                break;
            case R.id.rbt_gold_vip:
                if (POSITION != -1 && POSITION == 4) {
                    mRbtGoldVip.setChecked(false);
                    POSITION = -1;
                } else {
                    setNoChecked(POSITION);
                    POSITION = 4;
                }
                break;
            case R.id.rbt_blue_vip:
                if (POSITION != -1 && POSITION == 5) {
                    mRbtBlueVip.setChecked(false);
                    POSITION = -1;
                } else {
                    setNoChecked(POSITION);
                    POSITION = 5;
                }
                break;
        }
        if(POSITION!=-1)mTvLevel.setText(String.format(getString(R.string.member_style),levels[POSITION]));
    }

    public void setNoChecked(int position) {
        switch (position) {
            case 0:
                mRbtGoldChampion.setChecked(false);
                break;
            case 1:
                mRbtBlueChampion.setChecked(false);
                break;
            case 2:
                mRbtGoldDiamond.setChecked(false);
                break;
            case 3:
                mRbtBlueDiamond.setChecked(false);
                break;
            case 4:
                mRbtGoldVip.setChecked(false);
                break;
            case 5:
                mRbtBlueVip.setChecked(false);
                break;
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }


}
